<template>
  <div class="login-wrap">
    <div class="ms-title">欢迎使用物流系统</div>
    <div class="ms-login">
      <template>
        <el-radio class="radio" label="company">用户</el-radio>
        <el-radio class="radio" style="float: right" label="admin"
          >管理员</el-radio
        >
      </template>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="0px"
        class="demo-ruleForm"
        style="margin-top: 30px"
      >
        <el-form-item prop="username">
          <el-input
            v-model="ruleForm.username"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            placeholder="请输入密码"
            v-model="ruleForm.password"
            @keyup.enter.native="submitForm('ruleForm')"
          ></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >登录</el-button
          >
        </div>

        <el-row style="margin-top: 20px">
          <el-col :span="12"
            ><el-button type="text" @click="onPasswrod"
              >忘记密码？</el-button
            ></el-col
          >
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 3,
            max: 16,
            message: "长度在 3 到 16 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 16,
            message: "长度在 3 到 16 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
          this.$router.push("/main");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    onPasswrod() {
      this.$alert("请联系管理员重置密码", "密码找回");
    },
  },
  // resetForm(formName) {
  //   this.$refs[formName].resetFields();
  // },
};
</script>

<style scoped>
.login-wrap {
  position: relative;
  width: 100%;
  height: 720px;
  background-image: url("../assets/img/background.jpg");
  background-size: 100% 100%;
}

.ms-title {
  position: absolute;
  top: 50%;
  width: 100%;
  margin-top: -230px;
  text-align: center;
  font-size: 30px;
  color: #fff;
}

.ms-login {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 300px;
  height: 230px;
  margin: -150px 0 0 -190px;
  padding: 40px;
  border-radius: 5px;
  background: #fff;
}
.login-btn {
  text-align: center;
}
.login-btn button {
  width: 100%;
  height: 36px;
}
</style>
